﻿function demonPage() {
    var self = this;

    //Inherit the CUIpage
    CUIPage.call(this);

    //initial submit event
    this.pageEvent["validatePwd"] = function (e) {
        if (e.getValue() != self.demoPassword.getValue()) {
            return false;
        }
        return true;
    };

    //initial submit event
    this.pageEvent["submit"] = function () {
        if ($("fieldset").submitValidate()) {

            alert("success!")
        }
    };

    //initial error message
    this.pageEvent["error"] = function (e) {
        self.sidebarRight.show();
        var $validate_error = $("[validate_error='" + e.attr("id") + "']").closest(".section").find("h4");
        if ($validate_error.length > 0) {
            $validate_error.removeClass("text-success");
        }
    };

    //initial error message
    this.pageEvent["pass"] = function (e) {
        var $validate_error = $("[validate_error='" + e.attr("id") + "']").closest(".section").find("h4");
        if ($validate_error.length > 0) {
            $validate_error.addClass("text-success");
        }
    };

    //initial the side bar
    this.sidebarRight = $("#rightsider").sidebar();
    this.demoAccountID = $("[field='AccountID']").cTextbox({
        tip: "The account ID",
        attribute: {
            id: "AccountID",
            required: true,
            minlength: 5,
            OnValidateError: "error",
            OnValidatePass: "pass"
        }
    });
    this.demoPassword = $("[field='Password']").cTextbox({
        password: true,
        attribute: {
            id: "Password",
            required: true,
            minlength: 5,
            OnValidateError: "error",
            OnValidatePass: "pass"
        }
    });
    this.demoDPassword = $("[field='dPassword']").cTextbox({
        password: true,
        attribute: {
            id: "dPassword",
            required: true,
            validateType: "validatePwd",
            minlength: 5,
            OnValidateError: "error",
            OnValidatePass: "pass",
            ValidateErrorMessage: "The password should as same as not as same as Confirm Password!"
        }
    });
    this.demoPhone = $("[field='Phone']").cTextbox({
        tip: "Your Phone Number",
        attribute: {
            id: "Phone",
            validateType: CUICore.validateType.phone,
            OnValidateError: "error",
            OnValidatePass: "pass"
        }
    });
    this.demoEmail = $("[field='Email']").cTextbox({
        tip: "Your Email",
        attribute: {
            id: "Email",
            validateType: CUICore.validateType.email,
            OnValidateError: "error",
            OnValidatePass: "pass"
        }
    });
    this.demoFristName = $("[field='FristName']").cTextbox({
        tip: "Your Frist Name",
        attribute: {
            id: "FristName",
            OnValidateError: "error",
            OnValidatePass: "pass"
        }
    });
    this.demoTLastName = $("[field='LastName']").cTextbox({
        tip: "Your Last Name",
        attribute: {
            id: "LastName",
            OnValidateError: "error",
            OnValidatePass: "pass"
        }
    });
    this.demoButton = $("[field='submit']").cButton({
        attribute: {
            id: "submit",
            onItemClick: "submit"
        }
    });
}
demonPage.prototype = new CUIPage();

$(document).ready(function () {
    //inherit the CUIPage
    var currentPage = new demonPage();
    currentPage.InitialPage();
}); 
